package com.youdianstar.app.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.youdianstar.app.common.ex.setThrottleListener
import com.youdianstar.app.databinding.LayoutItemFaqContentBinding
import com.youdianstar.app.entity.FaqQuestionItem
import com.youdianstar.app.support.imp.IFaqListener


/**
 * File: FaqItemAdapter
 * Author: 82149 Create: 2023/7/25 10:34
 * Changes (from 2023/7/25)
 * --------------------------------------------------
 * description: FAQ 列表 新版
 * ---------------------------------------------------
 *
 */
class FaqItemAdapter(val context: Context, var dataList: List<FaqQuestionItem>, val clickListener: IFaqListener)
    : RecyclerView.Adapter<FaqItemAdapter.ListHolder>() {

    class ListHolder(val binding : LayoutItemFaqContentBinding) : RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListHolder {
        return ListHolder(LayoutItemFaqContentBinding.inflate(LayoutInflater.from(parent.context), parent, false))
    }

    override fun getItemCount(): Int {
        return dataList.size
    }

    override fun onBindViewHolder(holder: ListHolder, position: Int) {
        dataList[position].let { sort ->
            holder.binding.tvContent.text= sort.title

            holder.binding.faqContainer.setThrottleListener {
                clickListener.onQuestionClick(sort)
            }
        }
    }
}